let debounceouts = null
export const uniCommon = {
	/**
	 * @param { Function } fun 回调函数
	 * @param { Number } wait 防抖时间 
	 */
	debounce: function(fun, wait) {
		let debounceout = null
		return function() {
			let context = this;
			let args = arguments;
			if (debounceout) clearTimeout(debounceout)
			let is_now = !debounceout;
			debounceout = setTimeout(() => {
				debounceout = null
			}, wait)
			if (is_now) fun.apply(context, args)
		}
	},
	/**
	 * @param { Function } fun 回调函数
	 * @param { Number } wait 防抖时间 
	 */

	debounce2: function(fun, wait) {
		
		return function() {
			let context = this;
			let args = arguments;
			if (debounceouts) clearTimeout(debounceouts)
			let is_now = !debounceouts;
			debounceouts = setTimeout(() => {
				debounceouts = null
			}, wait)
			if (is_now) fun.apply(context, args)
		}
	},
	/**
	 *rich-text
	 * @param {string} content  rich-text 渲染的内容
	 * p_class  为p标签的class 若需要 需要自己写
	 * span_class 为 span标签的class 若有需要 需要自己写
	 * img_class 为 img 标签的class 若有需要 需要自己写
	 */
	richText: function(content) {
		content = content.replace(/&quot;/g, '"')
		content = content.replace(/&amp;/g, '&')
		content = content.replace(/&lt;/g, '<')
		content = content.replace(/&gt;/g, '>')
		content = content.replace(/&nbsp;/g, ' ')
		content = content.replace(/<p/gi, '<p class="p_class" ')
		content = content.replace(/<span/gi, '<span class="span_class" ')
		content = content.replace(/<img/gi, '<img class="img_class" ')
		return content
	},
	/**
	 * json 转 object
	 * @param {JSON} json 需要转换的json
	 */
	jsonToObject: function(json) {
		return JSON.parse(decodeURIComponent(json))
	},
	/**
	 * object 转 json
	 * @param {Object} obj 需要转换的obj
	 */
	objectToJson: function(obj) {
		return encodeURIComponent(JSON.stringify(obj))
	},
}